//
//  LGBloodPressureCell.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/3/6.
//

#import "LGBloodPressureCell.h"

#define leftMargin   viewPix(58)
#define itemWidth    (Screen_W-viewPix(32)-leftMargin-viewPix(10))/4.0

@interface LGBloodPressureCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *timeLabel;
/**  高压 */
@property (nonatomic , strong)UILabel *highLabel;
@property (nonatomic , strong)UILabel *highStatus;

/**  低压 */
@property (nonatomic , strong)UILabel *lowLabel;
@property (nonatomic , strong)UILabel *lowStatus;
/**  心率 */
@property (nonatomic , strong)UILabel *heartLabel;
@property (nonatomic , strong)UILabel *heartStatus;
/**   */
//@property (nonatomic , strong)UIButton *highBtn;
///**   */
//@property (nonatomic , strong)UIButton *lowBtn;
///**   */
//@property (nonatomic , strong)UIButton *heartBtn;
/**   */
@property (nonatomic , strong)UIButton *ecgBtn;
/**   */
@property (nonatomic , strong)NSDictionary *colorDic;

@end

@implementation LGBloodPressureCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.colorDic = @{@"重度":@"#E53C39",@"中度":@"#FF3535",@"偏高":@"#FEBB36",@"偏低":@"#4C87FD"};
        [self createSubView];
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
//    NSDictionary *iconDic = @{@"high":@"监测分数-偏高",@"low":@"监测分数-偏低"};
    self.timeLabel.text = LGNSString(dataDic[@"record_time"]);
    self.highLabel.text = LGNSString(dataDic[@"sbp"]);
    self.lowLabel.text = LGNSString(dataDic[@"dbp"]);
    self.heartLabel.text = LGNSString(dataDic[@"hr"]);
    NSString *highStatus = [LGNSString(dataDic[@"sbp_ab"]) isEmptyString]?@"":LGNSString(dataDic[@"sbp_ab"]);
    NSString *lowStatus = [LGNSString(dataDic[@"dbp_ab"]) isEmptyString]?@"":LGNSString(dataDic[@"dbp_ab"]);
    NSString *heartStatus = [LGNSString(dataDic[@"hr_ab"]) isEmptyString]?@"":LGNSString(dataDic[@"hr_ab"]);
    self.highStatus.text = highStatus;
    self.highStatus.textColor = [UIColor colorWithString:self.colorDic[highStatus]];
    self.lowStatus.text = lowStatus;
    self.lowStatus.textColor = [UIColor colorWithString:self.colorDic[lowStatus]];
    self.heartStatus.text = heartStatus;
    self.heartStatus.textColor = [UIColor colorWithString:self.colorDic[heartStatus]];
    
//    [self.highBtn setTitle:LGNSString(dataDic[@"sbp"]) forState:UIControlStateNormal];
//    [self.lowBtn setTitle:LGNSString(dataDic[@"dbp"]) forState:UIControlStateNormal];
//    [self.heartBtn setTitle:LGNSString(dataDic[@"hr"]) forState:UIControlStateNormal];
//    NSString *hightName = [dataDic[@"sbp_ab"] length]>0?self.colorDic[dataDic[@"sbp_ab"]]:@"";
//    NSString *lowName = [dataDic[@"dbp_ab"] length]>0?self.colorDic[dataDic[@"dbp_ab"]]:@"";
//    NSString *heartName = [dataDic[@"hr_ab"] length]>0?self.colorDic[dataDic[@"hr_ab"]]:@"";
//    [self.highBtn setImage:[UIImage imageNamed:hightName] forState:UIControlStateNormal];
//    [self.lowBtn setImage:[UIImage imageNamed:lowName] forState:UIControlStateNormal];
//    [self.heartBtn setImage:[UIImage imageNamed:heartName] forState:UIControlStateNormal];
//    if([dataDic[@"sbp_ab"] length]){
//        [self.highBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
//    }else{
//        [self.highBtn setButtonInsetsStyle:LGButtonInsetsStyleLeft marginSpace:0];
//    }
//    
//    if([dataDic[@"dbp_ab"] length]>0){
//        [self.lowBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
//    }else{
//        [self.lowBtn setButtonInsetsStyle:LGButtonInsetsStyleLeft marginSpace:0];
//    }
//    
//    if([dataDic[@"hr_ab"] length]>0){
//        [self.heartBtn setButtonInsetsStyle:LGButtonInsetsStyleRight marginSpace:2];
//    }else{
//        [self.heartBtn setButtonInsetsStyle:LGButtonInsetsStyleLeft marginSpace:0];
//    }
   
    if([dataDic[@"ecg_id"] integerValue]>0){
        [self.ecgBtn setImage:[UIImage imageNamed:@"血压-心电图Select"] forState:UIControlStateNormal];
        [self.ecgBtn setTitle:@"" forState:UIControlStateNormal];
        self.ecgBtn.userInteractionEnabled = YES;
    }else{
        [self.ecgBtn setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        [self.ecgBtn setTitle:@"--" forState:UIControlStateNormal];
        self.ecgBtn.userInteractionEnabled = NO;
    }
}

//查看心电图
-(void)checkECGDetailAction{
    if(self.delegate && [self.delegate respondsToSelector:@selector(checkECGDetail:)]){
        [self.delegate checkECGDetail:self.dataDic];
    }
}


-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.timeLabel];
    [self.baseView addSubview:self.highLabel];
    [self.baseView addSubview:self.highStatus];
    [self.baseView addSubview:self.lowLabel];
    [self.baseView addSubview:self.lowStatus];
    [self.baseView addSubview:self.heartLabel];
    [self.baseView addSubview:self.heartStatus];
    [self.baseView addSubview:self.ecgBtn];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(self.contentView).offset(viewPix(16));
        make.top.right.equalTo(self.contentView).offset(-viewPix(16));
    }];
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView).offset(viewPix(12));
        make.centerY.equalTo(self.baseView);
    }];
    [self.highLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.timeLabel);
        make.centerX.equalTo(self.baseView.mas_left).offset(leftMargin+itemWidth/2.0);
    }];
    
    [self.highStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.highLabel.mas_right).offset(viewPix(3));
        make.bottom.equalTo(self.highLabel);
    }];
    
    [self.lowLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.baseView.mas_left).offset(leftMargin+itemWidth*3/2.0);
        make.centerY.equalTo(self.highLabel);
    }];
    
    [self.lowStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.lowLabel.mas_right).offset(viewPix(3));
        make.bottom.equalTo(self.lowLabel);
    }];
    
    [self.heartLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.baseView.mas_left).offset(leftMargin+itemWidth*5/2.0);
        make.centerY.equalTo(self.highLabel);
    }];
    
    [self.heartStatus mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.heartLabel.mas_right).offset(viewPix(3));
        make.bottom.equalTo(self.heartLabel);
    }];
    
    [self.ecgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.baseView.mas_left).offset(leftMargin+itemWidth*3);
        make.width.equalTo(@(itemWidth));
        make.height.equalTo(@(viewPix(20)));
        make.centerY.equalTo(self.highLabel);
    }];
    
}

-(UIView *)baseView{
    if(!_baseView){
        _baseView = [[UIView alloc] init];
        _baseView.backgroundColor = [UIColor colorWithString:@"#F5FBFF"];
    }
    return _baseView;
}

-(UILabel *)timeLabel{
    if(!_timeLabel){
        _timeLabel = [UILabel lableWithText:@"" colorString:@"#606266" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _timeLabel;
}

-(UILabel *)highLabel{
    if(!_highLabel){
        _highLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _highLabel;
}

-(UILabel *)highStatus{
    if(!_highStatus){
        _highStatus = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _highStatus;
}

-(UILabel *)lowLabel{
    if(!_lowLabel){
        _lowLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _lowLabel;
}

-(UILabel *)lowStatus{
    if(!_lowStatus){
        _lowStatus = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _lowStatus;
}

-(UILabel *)heartLabel{
    if(!_heartLabel){
        _heartLabel = [UILabel lableWithText:@"" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentCenter lines:1];
    }
    return _heartLabel;
}

-(UILabel *)heartStatus{
    if(!_heartStatus){
        _heartStatus = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(14) textAlignment:NSTextAlignmentLeft lines:1];
    }
    return _heartStatus;
}

//-(UIButton *)highBtn{
//    if(!_highBtn){
//        _highBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#282828" imageName:@""];
//        _highBtn.userInteractionEnabled = NO;
//    }
//    return _highBtn;
//}
//
//-(UIButton *)lowBtn{
//    if(!_lowBtn){
//        _lowBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#282828" imageName:@""];
//        _lowBtn.userInteractionEnabled = NO;
//    }
//    return _lowBtn;
//}
//
//
//-(UIButton *)heartBtn{
//    if(!_heartBtn){
//        _heartBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#282828" imageName:@""];
//        _heartBtn.userInteractionEnabled = NO;
//    }
//    return _heartBtn;
//}

-(UIButton *)ecgBtn{
    if(!_ecgBtn){
        _ecgBtn = [UIButton buttonWithTitle:@"--" titleFont:LGFont(16) textColor:@"#282828" imageName:@""];
        [_ecgBtn addTarget:self action:@selector(checkECGDetailAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _ecgBtn;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
